import { http } from "../http"
import { ElMessage } from "element-plus"
export function login(data) {

    return http('login', 'post', data).then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
export function getUsers(params) {
    return http("users", "get", {}, params).then(res => {
        return res.data

    })
}
export function getMenus() {
    return http("menus", "get").then(res => {
        return res.data
    })
}
//获取权限列表
export function getRights(type) {
    return http(`rights/${type}`, "get").then(res => {
        return res.data
    })
}
//商品列表
export function getGoods(params) {
    return http("goods", "get", {}, params).then(res => {
        return res.data
    })
}
//添加商品
export function addGoods(data) {
    return http("goods", "post", data).then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: "商品添加成功"
        })
        return res.data
    })
}
//根据id查询商品详情
export function seeGoods(id) {
    return http(`goods/${id}`, "get").then(res => {

        return res.data
    })
}
//编辑商品
export function editGoods(id, data) {
    return http(`goods/${id}`, "put", data).then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//删除商品
export function delectGoods(id) {
    return http(`goods/${id}`, "delete").then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//商品分类列表
export function getCate(params) {
    return http("categories", "get", {}, params).then(res => {
        return res.data
    })
}
export function getParentCate(params) {
    return http("categories", "get", {}, params).then(res => {
        return res.data
    })
}
//添加分类
export function addCate(data) {
    return http("categories", "post", data).then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//编辑分类
export function editCate(id, data) {
    return http(`categories/${id}`, "put", data).then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//删除分类
export function delectCate(id) {
    return http(`categories/${id}`, "delete").then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//获取订单列表
export function getOrders(params) {
    return http("orders", "get", {}, params).then(res => {
        return res.data
    })
}
//修改订单列表
export function editOrders(id, data) {
    return http(`orders/${id}`, "put", data).then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//查看订单详情
export function seeOrders(id) {
    return http(`orders${id}`, "get").then(res => {
        return res.data
    })
}
//获取参数列表
export function getParams(id, params) {
    return http(`categories/${id}/attributes`, "get", {}, params).then(res => {

        return res.data
    })
}
//添加参数
export function addParams(id, data) {
    return http(`categories/${id}/attributes`, "post", data).then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//编辑提交参数
export function editParams(id, attrId, data) {
    return http(`categories/${id}/attributes/${attrId}`, "put", data).then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//删除参数
export function delectParams(id, attrId) {
    return http(`categories/${id}/attributes/${attrId}`, "delete").then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//获取数据报表
export function getReports() {
    return http("reports/type/1", "get").then(res => {
        return res.data
    })
}
//添加用户
export function addUsers(data) {
    return http("users", "post", data).then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//修改用户状态
export function changeUserStatus(id, type) {
    return http(`users/${id}/state/${type}`, "put").then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//编辑用户提交
export function exidUsers(id, data) {
    return http(`users/${id}`, "put", data).then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//删除单个用户
export function delectUser(id) {
    return http(`users/${id}`, "delete").then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//根据id查询rid
export function getRid(id) {
    return http(`users/${id}`, "get").then(res => {
        return res.data
    })
}
//分配用户角色
export function assignRoles(id, rid) {
    return http(`users/${id}/role`, "put", { rid }).then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//获取角色列表
export function getRoles() {
    return http("roles", "get").then(res => {
        return res.data
    })
}
//添加角色
export function addRoles(data) {
    return http("roles", "post", data).then(res => {
        return res.data
    })
}
//编辑提交角色
export function exidRoles(id, data) {
    return http(`roles/${id}`, "put", data).then(res => {
        return res.data
    })
}
//删除角色
export function delectRoles(id) {
    return http(`roles/${id}`, "delete").then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//删除角色指定权限
export function delectRolesRightS(roleId, rightId) {
    return http(`roles/${roleId}/rights/${rightId}`, "delete").then(res => {
        ElMessage({
            showClose: true,
            type: "success",
            message: res.meta.msg
        })
        return res.data
    })
}
//角色授权
export function setRolesRights(roleId,data){
    return http(`roles/${roleId}/rights`,"post",data).then(res=>{
        ElMessage ({
            showClose:true,
            type:"success",
            message :res.meta.msg
        
       })
        return res.data
    })
}
//上传图片
export function addUpload(data) {
    return http("upload", "post", data).then(res => {
        return res.data
    })
}








